<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>

<%@ page import="java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>连锁店配置管理</title>
<%@ include file="../../common/Style.jsp"%>
<script>
$(document).ready(function(){
	parent.$.messager.progress('close'); 
});
function changeChainStore(){
	var chainStoreId = $("#chainId").val();
	if (chainStoreId == 0){
		clearChainStoreConf();
	} else {
		var params="formBean.chainStoreConf.chainId=" + chainStoreId;
		$.post("<%=request.getContextPath()%>/actionChain/chainMgmtJSON!getChainStoreConf",params, backProcessGetChainStore,"json");
	}
}

function backProcessGetChainStore(data){
	var response =  data.response;
	var returnCode = response.returnCode;

	if (returnCode != SUCCESS){
		$.messager.alert('错误', response.message, 'error');
		clearChainStoreConf();
	} else {
		var chainStoreConf = response.returnValue;
	
		if (chainStoreConf != null){
			 
			 var discountAmtType = chainStoreConf.discountAmtType;//价格设置
			 var printTemplate = chainStoreConf.printTemplate;//小票机纸宽度
			 var printCopy = chainStoreConf.printCopy;//小票打印份数
			 var hideDiscountPrint = chainStoreConf.hideDiscountPrint;//小票打印折扣
			 var minDiscountRate = chainStoreConf.minDiscountRate;//销售最低折扣
			 var defaultDiscount = chainStoreConf.defaultDiscount;//销售默认折扣
			 var discount2020Spring = chainStoreConf.discount2020Spring;//2020春货品折扣
			 var discount2020Summer = chainStoreConf.discount2020Summer;
			 var discount2020Auto = chainStoreConf.discount2020Auto;
			 var discount2020Winter = chainStoreConf.discount2020Winter;			 
			 var defaultVipScoreMultiple = chainStoreConf.defaultVipScoreMultiple;//VIP默认积分			
			 var vipScoreCashRatio = chainStoreConf.vipScoreCashRatio;//VIP积分换现金
			 var allowVIPScore = chainStoreConf.allowOtherVIPUseVIPScore;//跨连锁店使用vip积分兑换			 
			 var prepaidUsage = chainStoreConf.allowMyPrepaidCrossStore;//跨连锁店使用预付金
			 var prepaidType = chainStoreConf.prepaidCalculationType;//预存金 使用计划
			 var prepaidPasswordRequired = chainStoreConf.prepaidPasswordRequired;//预存金 充值/消费安全策略
			 var quertReportMonth = chainStoreConf.quertReportMonth;//查询报表限制月份
			 var isHiddenOrder = chainStoreConf.isHiddenOrder;//隐藏单据设置
			 var isOpenBrandDiscountCheck = chainStoreConf.isOpenBrandDiscountCheck;//是否开启品牌折扣校验
			 var address = chainStoreConf.address;//连锁店地址 打印于小票
			 var shippingAddress = chainStoreConf.shippingAddress;//调货联系地址和电话
			 
			 			 
			 $("#amtType").val(discountAmtType).attr("selected", true);
			 $("#printTemplate").val( printTemplate);
			 $("#printCopy").val( printCopy);
			 $("#minDiscountRate").val( minDiscountRate);
			 $("#defaultDiscount").val( defaultDiscount);
			 $("#discount2020Spring").val(discount2020Spring);
			 $("#discount2020Summer").val(discount2020Summer);
			 $("#discount2020Auto").val(discount2020Auto);
			 $("#discount2020Winter").val(discount2020Winter);

			 $("#isOpenBrandDiscountCheck").val(isOpenBrandDiscountCheck);
			 $("#quertReportMonth").val(quertReportMonth);
			 $("#isHiddenOrder").val(isHiddenOrder);
			 $("#defaultVipScoreMultiple").val(defaultVipScoreMultiple);
			 $("#vipScoreUsage").val(allowVIPScore);
			 $("#vipScoreCashRatio").val( vipScoreCashRatio);			 			 
			 $("#shippingAddress").val(shippingAddress);
			 $("#hideDiscountPrint").val(hideDiscountPrint);
			 $("#prepaidUsage").val(prepaidUsage);
			 $("#prepaidType").val(prepaidType);		
			 $("#prepaidPasswordRequired").val(prepaidPasswordRequired);	
			 $("#isOpenBrandDiscountCheck").val(isOpenBrandDiscountCheck);			 
			 $("#address").val(address);
			 $("#shippingAddress").val(shippingAddress);

		}
	}
}

function editChainConf(){
	var params=$("#EditChainConfForm").serialize(); 
	if (validateChainConf()) 
	    $.post("<%=request.getContextPath()%>/actionChain/chainMgmtJSON!saveChainStoreConf",params, backProcessEditChainConf,"json");
}

function backProcessEditChainConf(data){
	var response =  data.response;
	var returnCode = response.returnCode;

	if (returnCode != SUCCESS){
		$.messager.alert('错误', response.message, 'error');
	} else {
		$.messager.alert('', "成功更新。\n如果有开启的零售单据页面，预存金冲值页面，请关闭之后重新打开，配置才能生效", 'info');
	}
}

function validateChainConf(){
	var chainStoreId = $("#chainId").val();
	if (chainStoreId == 0){
		$.messager.alert('', "选择连锁店之后更新", 'info');
		return false;
	} else {
 		//1. check the minDiscountRate
 		var minDiscountRate = $("#minDiscountRate").val();
 		if (!$.isNumeric(minDiscountRate)){
			$.messager.alert('错误', "最低折扣必须是数字", 'error');
			return false;
 	 	} else if (minDiscountRate <0 || minDiscountRate>1){
 	 		$.messager.alert('错误', "最低折扣必须是介于0和1之间的数字", 'error');
 	 		return false;
 	 	}

 	 	//2. 验证默认折扣
 		var defaultDiscount = $("#defaultDiscount").val();
 		if (!$.isNumeric(defaultDiscount)){
			$.messager.alert('错误', "默认折扣必须是数字", 'error');
			return false;
 	 	} else if (defaultDiscount <=0 || defaultDiscount>1){
 	 		$.messager.alert('错误', "默认折扣必须是介于0和1之间的数字", 'error');
 	 		return false;
 	 	} else if (defaultDiscount < minDiscountRate && minDiscountRate !=0){
 	 		$.messager.alert('错误', "默认折扣不能低于连锁店最低折扣", 'error');
 	 		return false;
 	 	}
	}
	return true;
}

function clearChainStoreConf(){
	 $("#printCopy").val(0);
	 $("#minDiscountRate").val(0);
	 $("#printTemplate").val(1);
	 $("#address").val("");
	 $("#hideDiscountPrint").val(0);
	 $("#prepaidPasswordRequired").val(0);
	 $("#quertReportMonth").val(0);
	 $("#isHiddenOrder").val(0);
}


</script>
</head>
<body>

	<s:form id="EditChainConfForm" action="/actionChain/chainMgmtJSP!save"
		method="POST" theme="simple" target="_blank" onsubmit="">
		<table width="90%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr class="PBAOuterTableTitale">
							<td height="48" colspan="6">- 通过这个界面管理员可以修改连锁店一些配置管理信息<br />
							</td>
						</tr>
						<tr class="InnerTableContent">
							<td width="180" height="32"><strong>连锁店</strong></td>
							<td width="250"><%@ include
									file="../include/SearchChainStore.jsp"%></td>
							<td width="78">&nbsp;</td>
							<td width="78">&nbsp;</td>
							<td width="182">&nbsp;</td>
							<td width="137">&nbsp;</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>价格设置</strong></td>
							<td><s:select id="amtType"
									name="formBean.chainStoreConf.discountAmtType"
									list="uiBean.amtTypeMap" listKey="key" listValue="value" /></td>
							<td></td>
							<td></td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>小票机纸宽度</strong></td>
							<td><s:select id="printTemplate"
									name="formBean.chainStoreConf.printTemplate"
									list="#{1:'58mm宽',2:'72mm宽'}" listKey="key" listValue="value" />
							</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>小票打印份数</strong></td>
							<td><s:textfield id="printCopy"
									name="formBean.chainStoreConf.printCopy" size="5"
									onkeypress='return is_number(event);' /></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>小票折扣打印</strong></td>
							<td><s:select id="hideDiscountPrint"
									name="formBean.chainStoreConf.hideDiscountPrint"
									list="#{0:'打印到小票',1:'隐藏折扣'}" listKey="key" listValue="value" /></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>销售最低折扣</strong></td>
							<td><s:textfield id="minDiscountRate"
									name="formBean.chainStoreConf.minDiscountRate" size="5" /></td>
							<td colspan="4">*当设置最低折扣为0.9，营业员输入货品折扣为0.8的时候，就不能过账.<br />'0'表示可以任意折扣卖;'1'表示所有产品不打折
							</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>销售默认折扣</strong></td>
							<td><s:textfield id="defaultDiscount"
									name="formBean.chainStoreConf.defaultDiscount" size="5" /></td>
							<td colspan="4">*在开单时，系统会自动使用默认折扣打折，比如在开张，做活动期间。之后请修改回'1'。</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>2020春货品折扣</strong></td>
							<td><s:select id="discount2020Spring"
									name="formBean.chainStoreConf.discount2020Spring"
									list="#{1:'默认开启',2:'停止'}" listKey="key" listValue="value" /></td>
							<td colspan="4">*2020春货品默认8.8折,vip默认8折,高于8折不能过帐</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>2020夏货品折扣</strong></td>
							<td><s:select id="discount2020Summer"
									name="formBean.chainStoreConf.discount2020Summer"
									list="#{1:'默认开启',2:'停止'}" listKey="key" listValue="value" /></td>
							<td colspan="4">*2020夏季货品默认8.8折,vip默认8折,高于8折不能过帐</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>2020秋货品折扣</strong></td>
							<td><s:select id="discount2020Auto"
									name="formBean.chainStoreConf.discount2020Auto"
									list="#{1:'默认开启',2:'停止'}" listKey="key" listValue="value" /></td>
							<td colspan="4">*2020秋货品默认8.8折,vip默认8折,高于8折不能过帐</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>2020冬货品折扣</strong></td>
							<td><s:select id="discount2020Winter"
									name="formBean.chainStoreConf.discount2020Winter"
									list="#{1:'默认开启',2:'停止'}" listKey="key" listValue="value" /></td>
							<td colspan="4">*2020冬季货品默认8.8折,vip默认8折,高于8折不能过帐</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>VIP默认积分</strong></td>
							<td><s:select id="defaultVipScoreMultiple"
									name="formBean.chainStoreConf.defaultVipScoreMultiple"
									list="#{1:'正常积分',2:'活动期间,两倍积分'}" listKey="key"
									listValue="value" /></td>
							<td colspan="4">*在活动期间,比如在开张，国庆，可以给所有vip客户设置双倍积分。之后请修改回正常积分体系。</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"><strong>VIP积分换现金</strong></td>
							<td><s:select id="vipScoreCashRatio"
									name="formBean.chainStoreConf.vipScoreCashRatio"
									list="#{0.01:'一百分换一元',0.02:'一百分换两元',0.03:'一百分换三元',0.04:'一百分换四元',0.05:'一百分换五元',0.06:'一百分换六元',0.08:'一百分换八元',0.1:'一百分换十元',1:'阶梯换分策略'}"
									listKey="key" listValue="value" /></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="35"><strong>跨连锁店使用vip积分兑换 </strong></td>
							<td><s:select id="vipScoreUsage"
									name="formBean.chainStoreConf.allowOtherVIPUseVIPScore"
									list="#{0:'只能自己连锁店vip兑换积分',1:'关联连锁店的vip也可以在本店铺消费积分',2:'所有其他连锁店的vip都可以在本店兑换积分'}"
									listKey="key" listValue="value" /></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="35"><strong>跨连锁店使用预付金 </strong></td>
							<td><s:select id="prepaidUsage"
									name="formBean.chainStoreConf.allowMyPrepaidCrossStore"
									list="#{0:'不允许我的vip的预存金在其他连锁店使用',1:'允许我的vip在关联连锁店充值/使用预存金'}"
									listKey="key" listValue="value" /></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="35"><strong>预存金 使用计划</strong></td>
							<td><s:select id="prepaidType"
									name="formBean.chainStoreConf.prepaidCalculationType"
									list="#{0:'正常预存 - 预存100抵用100',1:'1.1倍 - 预存500抵用550,预存1000抵用1100'}"
									listKey="key" listValue="value" /></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="35"><strong>预存金 充值/消费安全策略</strong></td>
							<td><s:select id="prepaidPasswordRequired"
									name="formBean.chainStoreConf.prepaidPasswordRequired"
									list="#{0:'不需要密码',1:'需要密码'}" listKey="key" listValue="value" />
							</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						
						<tr class="InnerTableContent">
							<td height="35"><strong>查询报表限制月份</strong></td>
							<td><s:select id="quertReportMonth"
									name="formBean.chainStoreConf.quertReportMonth"
									list="#{0:'不限制',3:'3个月',6:'6个月',9:'9个月',12:'12个月'}" listKey="key" listValue="value" />
							</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						
						<tr class="InnerTableContent">
							<td height="35"><strong>隐藏单据设置</strong></td>
							<td><s:select id="isHiddenOrder"
									name="formBean.chainStoreConf.isHiddenOrder"
									list="#{0:'不隐藏',1:'隐藏'}" listKey="key" listValue="value" />
							</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						
						<tr class="InnerTableContent">
							<td height="35"><strong>是否开启品牌折扣校验</strong></td>
							<td><s:select id="isOpenBrandDiscountCheck"
									name="formBean.chainStoreConf.isOpenBrandDiscountCheck"
									list="#{0:'关闭',1:'开启'}" listKey="key" listValue="value" />
							</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						
						<tr class="InnerTableContent">
							<td height="35"><strong>连锁店地址 打印于小票</strong></td>
							<td><s:textfield id="address"
									name="formBean.chainStoreConf.address" maxLength="28" size="35" />
							</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="35"><strong>调货联系地址和电话</strong></td>
							<td><s:textfield id="shippingAddress"
									name="formBean.chainStoreConf.shippingAddress" maxLength="80"
									size="80" /></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="25"></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
						
						

						<tr class="InnerTableContent">
							<td height="25">&nbsp;</td>
							<td><input type="button" onclick="editChainConf();"
								value="更新配置信息" /></td>
							<td></td>
							<td></td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
						</tr>
					</table>
				</td>
			</tr>

		</table>
	</s:form>

</body>
</html>